package vn.igolf.geo;

public class Triangle {
	private Point[] p = new Point[3];
//	private Point point1;
//	private Point point2;
//	private Point point3;
	
	public Triangle (Point point1, Point point2, Point point0) {
		this.p[0] = point0;
		this.p[1] = point1;
		this.p[2] = point2;
	}
	
	public double area () {
		double s = Math.abs(p[0].getX()*(p[1].getY()-p[2].getY())+p[1].getX()*(p[2].getY()-p[0].getY())+p[2].getX()*(p[0].getY()-p[1].getY()))/2;
		return s;
	}
	public boolean pointInTriangle (Point m) {
		Triangle m1 = new Triangle(this.p[0], this.p[1], m);
		Triangle m2 = new Triangle(this.p[2], this.p[1], m);
		Triangle m3 = new Triangle(this.p[0], this.p[2], m);
		if (Math.abs(m1.area()+m2.area()+m3.area()-this.area())< Line.EPSILON)
		return true;
		else return false;
	}
}
